﻿
var picPer = {};
picPer.NameControl = null;
picPer.IdControl = null;
$(function () {

    var depId = $("#perCombo").val();
    var name = $("#textSearchPer").val();
    picPer.para = [{ Field: "DepId", Value: depId, Operator: "=" }, { Field: "UserName", Value: name, Operator: "co" }];

    $("#tbPicPer").datagrid({
        url: '/Logic/BD/UserAjax.aspx?method=GetUserList',
        loadMsg: '数据加载中请稍后……',
        pagination: true,
        queryParams: { SearchData: JSON.stringify(picPer.para) },
        rownumbers: true,
        idField: "ID",
        fitColumns: true,
        columns: [[
            {
                field: 'ck', checkbox: true, width: 30
            },

                    {
                        field: 'UserName', title: '姓名', sortable: true, width: 100, align: "center"
                    }, {
                        field: 'DepName', title: '部门', sortable: true, width: 100, align: "center"
                    },
                         {
                             field: 'PosName', title: '岗位', sortable: true, width: 80, align: "center"
                         }


        ]],
        singleSelect: true,
        pageSize: 20,
        pageList: [20, 50, 100],
        striped: true,
        onDblClickRow: function (rowIndex, rowData) {
            picPer.NameControl.textbox("setText", rowData.UserName);
            picPer.NameControl.textbox("setValue", rowData.UserName);
            picPer.NameControl.nextAll("input[type=hidden]:first").val(rowData.ID);
            $("#tbPicPer").datagrid("unselectAll");
            $("#pickPerDiv").dialog("close");
            var depId = $("#perCombo").combobox("getValue");
            //去掉条件，重新加载人员
            $("#textSearchPer").val('');
            picPer.para = [{ Field: "DepId", Value: depId, Operator: "=" }, { Field: "UserName", Value: '', Operator: "co" }];
            $("#tbPicPer").datagrid("reload", {
                SearchData: JSON.stringify(picPer.para)
            });
        }
    });

    $("#perCombo").combobox({
        url: '/logic/CommonAjax/UserRelateAjax.aspx?method=GetDep',
        valueField: 'value',
        textField: 'text',
        width: 150,
        panelHeight: "auto",
        onChange: picPer.ReloadGrid
    });

    $("#textSearchPer").change(function () {

        picPer.ReloadGrid();
    });

    $.extend(com.dialogObj, { title: "选择人员", width: 470, height: 375 });
    $("#pickPerDiv").dialog(
            com.dialogObj
         );

    $("#pickPerDiv").dialog("close");
});



picPer.ReloadGrid = function () {
    var depId = $("#perCombo").combobox("getValue");
    var name = $("#textSearchPer").val();
    picPer.para = [{ Field: "DepId", Value: depId, Operator: "=" }, { Field: "UserName", Value: name, Operator: "co" }];

    $("#tbPicPer").datagrid("reload", {
        SearchData: JSON.stringify(picPer.para)
    });
}

picPer.Cancel = function () {
    $("#pickPerDiv").dialog("close");

    //去掉条件，重新加载人员
    $('#perCombo').combobox('setValue', '');
    $("#textSearchPer").val('');
    picPer.para = [{ Field: "DepId", Value: '', Operator: "=" }, { Field: "UserName", Value: '', Operator: "co" }];
    $("#tbPicPer").datagrid("reload", {
        SearchData: JSON.stringify(picPer.para)
    });
}

picPer.Confirm = function () {
    var row = $("#tbPicPer").datagrid("getSelected");
    if (row) {
        picPer.NameControl.textbox("setText", row.UserName);
        picPer.NameControl.textbox("setValue", row.UserName);
     //   console.log(picPer.NameControl.nextAll("input[type=hidden]:first"));
        picPer.NameControl.nextAll("input[type=hidden]:first").val(row.ID);
        $("#tbPicPer").datagrid("unselectAll");
        $("#pickPerDiv").dialog("close");
        
        //去掉条件，重新加载人员
        var depId = $("#perCombo").combobox("getValue");

        $("#textSearchPer").val('');
        picPer.para = [{ Field: "DepId", Value: depId, Operator: "=" }, { Field: "UserName", Value: '', Operator: "co" }];
        $("#tbPicPer").datagrid("reload", {
            SearchData: JSON.stringify(picPer.para)
        });
    }
    else {
        com.message("information", "请选择一条数据");
    }

}

picPer.open = function (target) {
    picPer.NameControl = target;
    $("#pickPerDiv").dialog("open");
}